package cn.edu.lingnan.lsqn.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.cdahua.basic.dao.BaseDao;
import cn.cdahua.basic.model.Pager;
import cn.edu.lingnan.lsqn.model.Article;
import cn.edu.lingnan.lsqn.model.ArticleType;

@Repository("articleDao")
public class ArticleDao extends BaseDao<Article> implements IArticleDao {

	@Override
	public Pager<Article> find() {
		String hql = "from Article a";
		return this.find(hql);
	}

	@Override
	public List<Article> listByUserId(int uid) {
		String hql = "from Article a where a.user.id=?";
		return this.list(hql, uid);
	}

	@Override
	public Pager<Article> findByUserId(int uid) {
		String hql = "from Article a where a.user.id=?";
		return this.find(hql, uid);
	}

	@Override
	public Pager<Article> findByStatus(ArticleType status) {
		String hql = "from Article a where a.status=?";
		return this.find(hql, status);
	}

	@Override
	public Pager<Article> findByUserIdAndStatus(int uid, ArticleType status) {
		String hql = "from Article a where a.user.id=? and a.status=?";
		return this.find(hql, new Object[]{uid,status});
	}

}
